const dialogueList = [];

export async function dialogue(content, role = 'user') {
    dialogueList.push({role, content});
    const resp = await fetch(
        'http://localhost:1234/v1/chat/completions',
        {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                'messages': dialogueList,
            }),
        },
    );
    const message = (await resp.json()).choices[0].message;
    message.content = message.content.replace(/<think>[\s\S]*<\/think>/, '').replace('/\n/g', '');
    dialogueList.push(message);
    return message.content;
}
